﻿#ifndef CMODBUSUNITBASE_H
#define CMODBUSUNITBASE_H

#include <QObject>
#include <shlib/viewmodel/imodel.h>
#include <shlib/iottypedef.h>

class CModbusUnitBase : public IModel
{
    Q_OBJECT
public:
    enum EModbusUnitCol {
        EMapId,
        EName,
        ERegType,
        EAddress,
        EFilter,
        EInvalid
    };

    QString map_id;
    QString name;

    ESigType map_type;

    int reg_type;
    int address;

    bool isfilter;

    bool is_init = false;
    bool m_ischange = false;
    bool m_isDelete = false;

    EOptType opt_type = EOptType::EOptUnDefine;

    explicit CModbusUnitBase(int colnum, ESigType maptype, QObject *parent = nullptr);

    void commit();

signals:

public:
    virtual QString getFieldNameByCol(int col)override;

    virtual QVariant getFieldValueByFielddName(const QString& name)override;

    virtual void setFieldValueByCol(int col, const QVariant& value)override;

    virtual QJsonObject toJson()override;

    virtual void fromJson(const QJsonObject &obj)override;

    virtual QSharedPointer<IModel> createEmpty()override;

    virtual void changeBgColor(bool ischange);

    virtual bool checkData();

    virtual void deleteReset();
};

#endif // CMODBUSUNITBASE_H
